<include file="Public/header"/>
<body class="body-bg">
<if condition="$info['id'] gt 0">
    <div class="park-header">
        <div class="park-header__title">修改支付密码</div>
        <div class="park-header__left" onclick="window.location='/Home/User/index/';">
            <i class="iconfont icon-fanhui"></i>
        </div>
    </div>
    <div class="container">
        <form onsubmit="return edit_pwd({$info.id});">
            <div class="password-form">
                <div class="password-group">
                    <i class="password-icon iconfont icon-lock"></i>
                    <input class="password-input" type="password" maxlength="6" id="o_pwd" onkeyup="this.value = this.value.replace(/[^\d]/g, '')" placeholder="请输入旧密码">
                </div>
                <div class="password-group">
                    <i class="password-icon iconfont icon-lock"></i>
                    <input class="password-input" type="password" maxlength="6" id="pwd" onkeyup="this.value = this.value.replace(/[^\d]/g, '')" placeholder="请输入新密码">
                </div>
                <div class="password-group">
                    <i class="password-icon iconfont icon-lock"></i>
                    <input class="password-input" type="password" maxlength="6" id="re_pwd" onkeyup="this.value = this.value.replace(/[^\d]/g, '')" placeholder="请再次确认密码">
                </div>
            </div>
            <button class="password-btn" type="submit">确定</button>
        </form>
    </div>
<else />
    <div class="park-header">
        <div class="park-header__title">新增支付密码</div>
        <div class="park-header__left" onclick="window.location='/Home/User/index/';">
            <i class="iconfont icon-fanhui"></i>
        </div>
    </div>
    <div class="container">
        <form onsubmit="return add_pwd();">
            <div class="password-form">
                <div class="password-group">
                    <i class="password-icon iconfont icon-lock"></i>
                    <input class="password-input" id="pwd" type="password" maxlength="6" onkeyup="this.value = this.value.replace(/[^\d]/g, '')" placeholder="请输入6位数字组成的密码">
                </div>
                <div class="password-group">
                    <i class="password-icon iconfont icon-lock"></i>
                    <input class="password-input" id="re_pwd" type="password" maxlength="6" onkeyup="this.value = this.value.replace(/[^\d]/g, '')" placeholder="请再次确认密码">
                </div>
            </div>
            <button class="password-btn" type="submit">确定</button>
        </form>
    </div>
</if>
</body>
<script src="__ROOT__/Public/Home/layer/layer.js"></script>
<script>
    function add_pwd(){
        var pwd = $('#pwd').val();
        if(pwd.length<6 || !pwd){
            layer.open({
                content:'请输入6位数字密码'
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
            $('#pwd').focus();
            return false;
        }
        var re_pwd = $('#re_pwd').val();
        if(re_pwd.length<6 || !pwd){
            layer.open({
                content:'请输入6位数字确认密码'
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
            $('#re_pwd').focus();
            return false;
        }
        if(pwd!=re_pwd){
            layer.open({
                content:'两次输入的密码不一致'
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
            return false;
        }
        $.post('/Home/User/pay_pwd/',{pwd:pwd,re_pwd:re_pwd,act:'add'},function(data){
            layer.open({
                content:data.msg
                ,btn: ['确定']
                ,yes: function(index){
                    if(data.code==200) {
                        window.location = '/Home/User/index/';
                    }
                    layer.closeAll();
                }
            });
        },'json');
        return false;
    }
    function edit_pwd(id){
        var o_pwd = $('#o_pwd').val();
        if(o_pwd.length<6 || !o_pwd){
            layer.open({
                content:'请输入6位数字原密码'
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
            $('#o_pwd').focus();
            return false;
        }
        var pwd = $('#pwd').val();
        if(pwd.length<6 || !pwd){
            layer.open({
                content:'请输入6位数字密码'
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
            $('#pwd').focus();
            return false;
        }
        var re_pwd = $('#re_pwd').val();
        if(re_pwd.length<6 || !pwd){
            layer.open({
                content:'请输入6位数字确认密码'
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
            $('#re_pwd').focus();
            return false;
        }
        if(pwd!=re_pwd){
            layer.open({
                content:'两次输入的密码不一致'
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
            return false;
        }
        $.post('/Home/User/pay_pwd/',{pwd:pwd,re_pwd:re_pwd,act:'edit',id:id,o_pwd:o_pwd},function(data){
            layer.open({
                content:data.msg
                ,btn: ['确定']
                ,yes: function(index){
                    if(data.code==200) {
                        window.location = '/Home/User/index/';
                    }
                    layer.closeAll();
                }
            });
        },'json');
        return false;
    }
</script>
</html>